<?php 
class annonce_offre extends MX_Controller{
	public $category;
	public function index($region='',$vPage='',$page=''){
		if($region=='page'){
			$region='';
			$page=$vPage;
		}
		$title='Offres ';
		$description='Consultez ';
		$keywords='annonces, offre, gratuit';
		$message_tous =0;
		$message_particuliers =0 ;
		$message_professionnels =0;
		
		$TopAnnonces=$annonces=array();
		if($region){			
			$regionObject=$this->model('annonce_models_region')->get_region($region);
			$title.=$regionObject->nom_region;
			if($regionObject->code_departement){
				//set session region
				$this->session->set_userdata('region', $regionObject->code_departement);
			}
			$description.=$regionObject->nom_region;
			$keywords.=$regionObject->nom_region;
			$region=$regionObject->code_departement;
		}
		

		$this->load->library('session');
		$this->session->set_userdata('type','offre');

		$chercher_annonce=$this->load->Module('annonce/chercher');
		$chercher_annonce->load_session();
		$chercher_annonce->region=$region;
		$chercher_annonce->category=$this->session->userdata('category_id');
		$chercher_annonce->type=$this->session->userdata('type');
		$chercher_annonce->page=$page;
		
		$ids_anonnces=$chercher_annonce->get_list_annonces();
		
		$message_tous =$chercher_annonce->nb;
		$message_particuliers='test '.$chercher_annonce->nb_particuliers;
		$message_professionnels =$chercher_annonce->nb_professionnels;
		
		$description.=$message_tous.' offres ';
		
		
		$product=$this->load->Module('product/show');
		if(!empty($ids_anonnces))
		foreach ($ids_anonnces as $id_annonce){
			$annonces[$id_annonce]=$product->get_info($id_annonce);
		}
		$message_tous.=' offres';
		$message_particuliers.=' offres' ;
		$message_professionnels.=' offres';
		if($region){
			$title.= " région ".$region;
			$description.= " région ".$region;
		}
		if($page){
			$title.= " Page ".$page;
			$description.= " Page ".$page;
		}
		$data=array(
				'title'=>$chercher_annonce->nb.' '.$title,
				'description'=>$description,
				'keywords'=>$keywords,
				'paging'=>$chercher_annonce->paging,
				'nb'=>$chercher_annonce->nb,
				'nb_particulier'=>$chercher_annonce->nb_particuliers,
				'nb_professionnells'=>$chercher_annonce->nb_professionnels,
				'message_tous'=>$message_tous,
				'message_particuliers'=>$message_particuliers ,
				'message_professionnels'=>$message_professionnels,
				'annonces'=>$annonces,
				'TopAnnonces'=>$TopAnnonces
		);
		
		$setting=$this->load->Module('setting/data');
		$data=$setting->data($data);
		$data['nav_class']['offre']='active';
		
		$this->view(
				array('header',
					'category',
					'footer'), 
				$data); // Display the page 
	} 

	public function page($page=''){
		if($page=='')$page=0;
		self::index('','',$page);
	}
}